package com.bree.erp.entity;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

@NamedQuery(name=InventoryAudit.QUERY_SELECT_ALL_INVENTORYAUDIT,
query = "SELECT ia FROM InventoryAudit ia")
@Entity
public class InventoryAudit implements CrudId<Long>{

	public static final String QUERY_SELECT_ALL_INVENTORYAUDIT = "selectAllInventoryAudit";
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;

	@ManyToOne
	private Inventory inventory;
	
	@OneToOne
	private Unit unit;
	
	private double quantity;
	
	@Enumerated(EnumType.STRING)
	private InventoryStatus status;
	
	
	public String getName() {
		if(this.inventory == null || this.inventory.getMasterItem() == null) {
			return null;
		}
		
		return inventory.getMasterItem().getName();
	}
	
	public String getDescription() {
		if(this.inventory == null || this.inventory.getMasterItem() == null) {
			return null;
		}
		
		return inventory.getMasterItem().getDescription();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the inventory
	 */
	public Inventory getInventory() {
		return inventory;
	}

	/**
	 * @param inventory the inventory to set
	 */
	public void setInventory(Inventory inventory) {
		this.inventory = inventory;
	}

	/**
	 * @return the unit
	 */
	public Unit getUnit() {
		return unit;
	}

	/**
	 * @param unit the unit to set
	 */
	public void setUnit(Unit unit) {
		this.unit = unit;
	}

	/**
	 * @return the quantity
	 */
	public double getQuantity() {
		return quantity;
	}

	/**
	 * @param quantity the quantity to set
	 */
	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}

	/**
	 * @return the status
	 */
	public InventoryStatus getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(InventoryStatus status) {
		this.status = status;
	}
	
}
